package service.impl;

import dao.StorageRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pojo.StorageRecord;
import service.StorageRecordService;

import java.util.List;

@Transactional
@Service("storageRecordService")
public class StorageRecordServiceImpl implements StorageRecordService {
    @Autowired
    private StorageRecordMapper storageRecordMapper;
    /**
     * 添加入库记录
     *
     * @param storageRecord
     * @return
     */
    @Override
    public boolean add(StorageRecord storageRecord) {
        boolean result=false;
        try {
            if(storageRecordMapper.add(storageRecord)>0){
                result=true;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 删除入库记录
     *
     * @param id
     * @return
     */
    @Override
    public boolean delete(int id) {
        boolean result=false;
        try {
            if(storageRecordMapper.delete(id)>0){
                result=true;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 修改入库记录
     *
     * @param storageRecord
     * @return
     */
    @Override
    public boolean update(StorageRecord storageRecord) {
        boolean result=false;
        try {
            if(storageRecordMapper.update(storageRecord)>0){
                result=true;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public boolean deleteBySupId(int supId) {
        return storageRecordMapper.deleteBySupId(supId)>0;
    }

    @Override
    public int selectCountBySupId(int supId) {
        return storageRecordMapper.selectCountBySupId(supId);
    }

    /**
     * 分页查询
     *
     * @param queryGoodsName 商品名称（模糊查询）
     * @param queryPayStatus 支付状态
     * @param id             供货商id
     * @param pageIndex      当前页数
     * @param pageSize       每页显示条数
     * @return
     */
    @Override
    public List<StorageRecord> selectPage(String queryGoodsName, String queryPayStatus, Integer id, Integer pageIndex, Integer pageSize) {
        return storageRecordMapper.selectPage(queryGoodsName,queryPayStatus,id,pageIndex,pageSize);
    }

    /**
     * 查询总记录数
     *
     * @param queryGoodsName
     * @param queryPayStatus
     * @param id
     * @return
     */
    @Override
    public int selectCount(String queryGoodsName, String queryPayStatus, Integer id) {
        return storageRecordMapper.selectCount(queryGoodsName,queryPayStatus,id);
    }

    /**
     * 根据id查询入库记录
     *
     * @param storageRecordId
     * @return
     */
    @Override
    public StorageRecord selectById(Integer storageRecordId) {
        if(storageRecordId==null || storageRecordId==0){
            return null;
        }
        return storageRecordMapper.selectById(storageRecordId);
    }
}
